import request from './request'

export interface CarouselTranslation {
  locale: string
  title: string
  subtitle: string
  cta_text: string
}

export interface Carousel {
  id?: number
  image?: string
  image_url?: string
  link?: string
  sort_order: number
  is_active: boolean
  translations: CarouselTranslation[]
  created_at?: string
  updated_at?: string
}

export interface CarouselListParams {
  page?: number
  page_size?: number
  is_active?: boolean
  ordering?: string
}

/**
 * 获取轮播图列表
 */
export const getCarousels = (params?: CarouselListParams) => {
  return request.get('/carousels/', { params })
}

/**
 * 获取轮播图详情
 */
export const getCarousel = (id: number) => {
  return request.get(`/carousels/${id}/`)
}

/**
 * 创建轮播图
 */
export const createCarousel = (data: FormData) => {
  return request.post('/carousels/', data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 更新轮播图
 */
export const updateCarousel = (id: number, data: FormData) => {
  return request.put(`/carousels/${id}/`, data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 删除轮播图
 */
export const deleteCarousel = (id: number) => {
  return request.delete(`/carousels/${id}/`)
}

/**
 * 切换轮播图激活状态
 */
export const toggleCarouselActive = (id: number) => {
  return request.patch(`/carousels/${id}/toggle_active/`)
}

